home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pasclern.zip / LINKLIST.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-01  |  2KB  |  54 lines

  1. PROGRAM linked_list_example;
  2.  
  3. TYPE next_pointer = ^full_name;
  4.  
  5.      full_name = RECORD
  6.        first_name : STRING[12];
  7.        initial    : CHAR;
  8.        last_name  : STRING[15];
  9.        next       : next_pointer;
  10.      END;
  11.  
  12. VAR  start_of_list : next_pointer;
  13.      place_in_list : next_pointer;
  14.      temp_place    : next_pointer;
  15.      index         : INTEGER;
  16.  
  17. BEGIN  (* main program *)
  18.                        (* generate the first name in the list *)
  19.   new(place_in_list);
  20.   start_of_list := place_in_list;
  21.   place_in_list^.first_name := 'John';
  22.   place_in_list^.initial := 'Q';
  23.   place_in_list^.last_name := 'Doe';
  24.   place_in_list^.next := NIL;
  25.                        (* generate another name in the list *)
  26.   temp_place := place_in_list;
  27.   new(place_in_list);
  28.   temp_place^.next := place_in_list;
  29.   place_in_list^.first_name := 'Mary';
  30.   place_in_list^.initial := 'R';
  31.   place_in_list^.last_name := 'Johnson';
  32.   place_in_list^.next := NIL;
  33.                   (* add 10 more names to complete the list *)
  34.   FOR index := 1 TO 10 DO
  35.   BEGIN
  36.     temp_place := place_in_list;
  37.     new(place_in_list);
  38.     temp_place^.next := place_in_list;
  39.     place_in_list^.first_name := 'William';
  40.     place_in_list^.initial := 'S';
  41.     place_in_list^.last_name := 'Jones';
  42.     place_in_list^.next := NIL;
  43.   END;
  44.                    (* display the list on the video monitor *)
  45.   place_in_list := start_of_list;
  46.   REPEAT
  47.     WRITE(place_in_list^.first_name);
  48.     WRITE(' ',place_in_list^.initial);
  49.     WRITELN(' ',place_in_list^.last_name);
  50.     temp_place := place_in_list;
  51.     place_in_list := place_in_list^.next;
  52.   UNTIL temp_place^.next = NIL;
  53. END.  (* of main program *)
  54.